package org.itboys.core.service.mongo.front;

import org.itboys.commons.ErrorException;
import org.itboys.commons.utils.tools.LongUtil;
import org.itboys.core.common.SundayCommonConstants;
import org.itboys.core.entity.mongo.SundayCommonMessage;
import org.itboys.mongodb.core.MongoDataSource;
import org.itboys.mongodb.service.BaseMongoService;
import org.itboys.param.ParamUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * Auther: 罗尧坤
 * Date: 2018/8/15
 * Description: 常见问题_微信服务类
 */

@Service
public class SundayFrontCommonMessageService extends BaseMongoService<SundayCommonMessage> {
    @Resource(name = "mobileDs")
    private MongoDataSource sundayDataSource;

    @Override
    protected MongoDataSource getMongoDataSource() {
        return sundayDataSource;
    }

    @Override
    protected Class<SundayCommonMessage> getEntityClass() {
        return SundayCommonMessage.class;
    }

    /**
     * 分页查询所有常见问题
     * @param request
     * @return
     */
    public List<SundayCommonMessage> select(HttpServletRequest request){
        Map<String, Object> param = ParamUtil.packageMongoExactParam(request);
        param.put("isDeleted", SundayCommonConstants.NO);

        List<SundayCommonMessage> list = super.pageQuery(request,param).getData();
        return list;
    }

    /**
     * 查询常见问题详情
     * @param id
     * @return
     */
    public SundayCommonMessage findOne(Long id){
        if (LongUtil.isNotZreo(id)){
            return super.getById(id);
        }else throw new ErrorException("id不能为空");
    }

}
